/**
 * 
 */
package cn.otrue.patienthealthmanager.socialshare;

import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

import com.umeng.socialize.bean.RequestType;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.bean.SocializeEntity;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.controller.listener.SocializeListeners.SnsPostListener;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import com.umeng.socialize.weixin.media.CircleShareContent;
import com.umeng.socialize.weixin.media.WeiXinShareContent;

/**
 * @author $shenshasha
 * @params
 * @return
 */
public class SocialShare {
	final UMSocialService mController =UMServiceFactory.getUMSocialService("com.umeng.share",RequestType.SOCIAL);								
	Context context;
	public Context getContext() {
		return context;
	}
	public void setContext(Context context) {
		this.context = context;
	}
	public void socialShare()
	{
		String appID ="wx945ef05e217a4c48";
		String appSecret ="6687aa5afdb60aaa515b223f7c16fa83";
		// 添加微信平台
		UMWXHandler wxHandler = new UMWXHandler(context,appID,appSecret);
		wxHandler.addToSocialSDK();
		// 支持微信朋友圈  
        UMWXHandler wxCircleHandler = new UMWXHandler(context, appID,appSecret);  
        wxCircleHandler.setToCircle(true);  
        wxCircleHandler.addToSocialSDK();  
     // 设置微信好友分享内容  
        WeiXinShareContent weixinContent = new WeiXinShareContent();  
     // 设置分享文字 
        weixinContent.setShareContent(Constant.wx_share_context);  
        // 设置title  
        weixinContent.setTitle(Constant.wx_circle_share_title);  
        // 设置分享内容跳转URL    
        weixinContent.setTargetUrl(Constant.wx_circle_share_content_target_url);  
     // 设置分享图片  
        mController.setShareMedia(weixinContent);  
  

        // 设置微信朋友圈分享内容 
        CircleShareContent circleMedia = new CircleShareContent();  
        circleMedia.setShareContent(Constant.wx_circle_share_context);  
     // 设置朋友圈title 
        circleMedia.setTitle(Constant.wx_circle_share_title);  
       // circleMedia.setShareImage(mUMImgBitmap);  
        circleMedia.setTargetUrl(Constant.wx_circle_share_content_target_url);  
        mController.setShareMedia(circleMedia);  
        mController.getConfig().setPlatforms(SHARE_MEDIA.WEIXIN,SHARE_MEDIA.WEIXIN_CIRCLE);
        mController.registerListener(mSnsPostListener);
     // 所有用户均可用
		mController.openShare((Activity) context, false);
	}
	SnsPostListener mSnsPostListener = new SnsPostListener() {
		@Override
		public void onStart() {}
		@Override
     	public void onComplete(SHARE_MEDIA platform, int stCode,SocializeEntity entity) 
		{
			if (stCode == 200) {Toast.makeText(context, "分享成功", Toast.LENGTH_SHORT).show();
     	} 
		else 
		{
			//Toast.makeText(EquipsNearby.this,"分享失败 : error code : " + stCode, Toast.LENGTH_SHORT).show();
     	}
	}
    };
	
}
